
const state = {
	token: uni.getStorageSync('accessToken') || '',
	userInfo: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo') : null,
};

const mutations = {
	LOGIN(state, opt) {
		state.token = opt.token;
	},
	UPDATE_LOGIN(state, token) {
		state.token = token;
	},
	LOGOUT(state) {
		state.token = undefined;
		state.userInfo = {}
		uni.clearStorage()
	},
	UPDATE_USERINFO(state, userInfo) {
		state.userInfo = userInfo;
		Cache.set(USER_INFO, userInfo);
	},
	//更新useInfo数据
	changInfo(state, payload) {
		state.userInfo[payload.amount1] = payload.amount2;
		Cache.set(USER_INFO, state.userInfo);
	},
};

const actions = {
	// USERINFO({
	// 	state,
	// 	commit
	// }, force) {
	// 	return new Promise(reslove => {
	// 		UserApi.getUserInfo().then(res => {
	// 			commit("UPDATE_USERINFO", res.data);
	// 			reslove(res.data);
	// 		})
	// 	}).catch(() => {

	// 	});
		
	// }
};

export default {
	state,
	mutations,
	actions
};
